#ifndef __USER__
#define __USER__

#include <mysql/mysql.h>

// SELECT tomb FROM users WHRER name = username;
int user_exist(MYSQL *db, const char *username);

// SELECT salt FROM users WHERE name = username;
int get_salt(MYSQL *db, const char *username, char *salt);

// SELECT passwd FROM users WHERE name = username;
int get_encrypted_password(MYSQL *db, const char *username, char *encrypted_password);

// UPDATE users SET lastlogin = current time WHERE name = username;
int update_login_time(MYSQL *db, const char *username);

int encrypt(const char *clear_text_password, const char *salt, char *encrypted_password);

int generate_salt(char *salt);

// INSERT INTO users (name, salt, passwd) VALUES (username, salt, encrypted_password);
int adduser(MYSQL *db, const char *username, const char *salt, const char *encrypted_password);
#endif // !__USER__
